# include <iostream>
# include <string>
# include <cmath>
# include <unordered_map>

using
namespace
std;

bool
is_prime(int
n) {
if (n <= 1)
{
return false;
}
for (int i = 2; i <= sqrt(n); ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}

int
find_closest_prime(int
n) {
int
increment = 1;
while (true) {
if (is_prime(n + increment)) {
return n + increment;
}
if (is_prime(n - increment)) {
return n - increment;
}
increment + +;
}
}

int
main()
{
    unordered_map < string, char > words_to_digits = {
    {"zero", '0'}, {"one", '1'}, {"two", '2'}, {"three", '3'}, {"four", '4'},
    {"five", '5'}, {"six", '6'}, {"seven", '7'}, {"eight", '8'}, {"nine", '9'}
};

string
word1, word2, word3;
cin >> word1 >> word2 >> word3;

try {
string number_str = "";
number_str += words_to_digits.at(word1);
number_str += words_to_digits.at(word2);
number_str += words_to_digits.at(word3);

int number = stoi(number_str);
cou << find_closest_prime(number) << endl;
} catch (const out_of_range & e) {
cout << "Wrong input" << endl;
}

return 0;
}